<!doctype html>
<html lang="zh-CN">
<head>
    <title>melon编辑</title>
    {% include 'admin/common/header.html' %}
</head>
<body class="pear-container">
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ melon.id }}" name="id" lay-verify="title"
                               autocomplete="off" placeholder="请输入编号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ melon.name }}" name="name" lay-verify="title"
                               autocomplete="off" placeholder="请输入名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ melon.type }}" name="type" lay-verify="title"
                               autocomplete="off" placeholder="请输入分类"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">产地</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ melon.origin }}" name="origin" lay-verify="title"
                               autocomplete="off" placeholder="请输入产地"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ melon.comment }}" name="comment" lay-verify="title"
                               autocomplete="off" placeholder="请输入描述"
                               class="layui-input">
                    </div>
                </div>
                {#                <div class="layui-form-item">#}
                {#                    <label class="layui-form-label"></label>#}
                {#                    <div class="layui-input-block">#}
                {#                        <ul id="selectParent" name="deptId" class="dtree" data-id="0"></ul>#}
                {#                    </div>#}
                {#                </div>#}


            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="melon-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>


{% include 'admin/common/footer.html' %}
<script>
    layui.use(['form', 'jquery', 'dtree'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let dtree = layui.dtree;

        dtree.renderSelect({
            elem: '#selectParent',
            url: '/api/v1/dept/department',
            method: 'get',
            selectInputName: {nodeId: 'deptId', context: 'deptName'},
            skin: 'layui',
            dataFormat: 'list',
            response: {treeId: 'deptId', parentId: 'parentId', title: 'deptName'},
            selectInitVal: "{{ melon.dept_id }}",
        });

        form.on('submit(melon-update)', function (data) {
            $.ajax({
                url: '/api/v1/melons/melon/' + data.field.id,
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.message, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload('tables');
                        });
                    } else {
                        layer.msg(result.message, {icon: 2, time: 1000});
                    }
                },
            });
            return false;
        });
    });
</script>
</body>
</html>